#!/bin/bash
# ### create by FlyShine 	###
# ### 2011年6月7日 			###
# ### version :  V0.1 		###
srcFile="$1";
prefix="$2";
version="$3";
dstFile="$4";
#排序,去重，去除前缀,若去除后为空则替换“.”
finalResult="";
sort $srcFile > $srcFile.sort;
uniq $srcFile.sort > $srcFile.uniq;
allFa=(`cat $srcFile.uniq`);

for f in ${allFa[@]}; do
  sed -i "s#$f/.*##g" $srcFile.uniq
done
sed -i "/^$/d" $srcFile

allFb=(`cat $srcFile.uniq`);
for f in ${allFb[@]}; do
	if [ "$f" == "$prefix" ];then
		finalResult="." 
		break;
	else
		finalResult="$finalResult\n`echo $f |sed  "s#$prefix/##g"`"
	fi
done
echo  -e "ver${version}=\"${finalResult}\"" >> $dstFile
rm $srcFile.sort $srcFile.uniq;